from flask_marshmallow.sqla import SQLAlchemyAutoSchema

from applications.extensions import ma
from applications.models import Dept
from marshmallow import fields

class DeptSchema(SQLAlchemyAutoSchema):
    class Meta:
        model = Dept  # table = models.Album.__table__
        # include_relationships = True  # 输出模型对象时同时对外键，是否也一并进行处理
        include_fk = True  # 序列化阶段是否也一并返回主键
        # fields= ["id","name"] # 启动的字段列表
        # exclude = ["id","name"] # 排除字段列表

class DeptOutSchema(ma.Schema):
    deptId = fields.Str(attribute="id")
    parentId = fields.Str(attribute="parent_id")
    deptName = fields.Str(attribute="dept_name")
    sort = fields.Integer()
    leader = fields.Str()
    phone = fields.Str()
    email = fields.Str()
    status = fields.Integer()
    remark = fields.Str()
    address = fields.Str()
    create_at = fields.DateTime()
    update_at = fields.DateTime()
